<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Topclass {

    var $CI;
    var $appsetingarray;

    public function __construct() {
        $this->CI = & get_instance();
        $this->CI->load->helper('url');
        //  include "top/TopSdk.php";
        $this->CI->load->library('top/top/TopClient');
        $this->CI->load->library('top/top/RequestCheckUtil');
        $this->CI->config->load('topapiconfig');
        $this->appsetingarray = $this->CI->config->item('website_oauth'); //  tobaokeapi
        // Do something with $params
    }

    public function get_topobj($classname) {//获得top的初始化对象，传入类名称
        $apiurl = "top/top/request/{$classname}";
        $this->CI->load->library($apiurl);
        $c = new TopClient;
        $appsetingarray = $this->appsetingarray;
       
        
        $c->appkey = $appsetingarray["appkey"]; //"21124740"
        $c->secretKey = $appsetingarray["appsecck"]; //"d6a8581eac74eb1fc5ad73bb846b3d53"
        return $c;
    }

    public function api_getSellercatsListGetRequest($classname, $nickname, $sessionkey = null) {//获得店铺分类api封装
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setNick($nickname);
        $resp = $c->execute($req);
        return $resp;
    }

    public function api_getShopGetRequest($classname, $nickname) {//获得shopidapi封装
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setFields("sid,cid,title,nick,desc,bulletin,pic_path,created,modified");
        $req->setNick($nickname);
        return $resp = $c->execute($req);
    }

    public function api_SellercenterSubusersGetRequest($classname, $nickname, $sessionkey = null) {//获得子帐号
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setNick($nickname);
        return $resp = $c->execute($req, $sessionkey);
    }

    public function api_getSellercenterRolesGetRequest($classname, $nickname, $sessionKey = null) {//获取帐号的子角色
        //收入大号获取下面包含的角色
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setNick($nickname);
        return $resp = $c->execute($req, $sessionKey);
    }

    public function api_getSellercenterRolemembersGetRequest($classname, $roleid, $sessionKey = null) {//
        //属于角色roleid获取下面所包含的客服昵等信息
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setRoleId($roleid);
        return $resp = $c->execute($req, $sessionKey);
    }

    public function api_getUserGetRequest($classname, $nickname, $sessionKey = null) {

        $c = $this->get_topobj($classname);
        $req = new $classname;
       $req->setFields("user_id,nick,sex,seller_credit,type,has_more_pic,item_img_num,item_img_size,prop_img_num,prop_img_size,auto_repost,promoted_type,status,alipay_bind,consumer_protection,avatar,liangpin,sign_food_seller_promise,has_shop,is_lightning_consignment,has_sub_stock,is_golden_seller,vip_info,magazine_subscribe,vertical_market,online_gaming");
       return $resp = $c->execute($req, $sessionKey);
    }
    
     public function api_TaobaokeItemsConvertRequest($classname, $proid, $pid, $sessionKey = null) {//根绝商品id和淘宝客pid对商品进行淘宝客转换
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setFields("click_url,num_iid,commission,commission_rate,commission_num,commission_volume");
        $req->setNumIids($proid);
        $req->setPid($pid);
        return $resp = $c->execute($req);
    }

    public function api_TaobaokeShopsConvertRequest($classname, $shopnick, $sessionKey = null) {//根据shop昵称获取淘宝客相应代码
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setFields("shop_title,click_url,commission_rate");
        $req->setSellerNicks($shopnick);
        $resp = $c->execute($req);
    }

    
 //获取买家信息
       public function api_UserBuyerGetRequest($classname,$sessionKey = null) {//根据shop昵称获取淘宝客相应代码
        $c = $this->get_topobj($classname);
        $req = new $classname;
        $req->setFields("user_id,nick,sex,buyer_credit,avatar,has_shop,vip_info");
       return $resp = $c->execute($req, $sessionKey);
       // $resp = $c->execute($req);
    }
    
    
    
    
    
    
    

}

/* End of file Someclass.php */